﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Mirror.CliMetadata
{
	public class MetadataRowRange<TRow>
		where TRow : IMetadataRow, new()
	{
		public int OwnerRowNumber { get; private set; }
		public MetadataTable<TRow> Table { get; private set; }
		public int FirstRowNumber { get; private set; }
		public int RowCount { get; private set; }

		public MetadataRowRange(
			int ownerRowNumber,
			MetadataTable<TRow> table,
			int firstRowNumber,
			int rowCount
			)
		{
			if (table == null) throw new ArgumentNullException("table");

			this.OwnerRowNumber = ownerRowNumber;
			this.Table = table;
			this.FirstRowNumber = firstRowNumber;
			this.RowCount = rowCount;
		}

		public TRow this[int index]
		{
			get { return this.Table.Rows[index + this.FirstRowNumber - 1]; }
		}
		public bool Contains(int rowNumber)
		{
			bool contains =
				(rowNumber >= this.FirstRowNumber)
				&& (rowNumber < (this.FirstRowNumber + this.RowCount))
				;
			return contains;
		}
		public TRow[] GetRows()
		{
			TRow[] rows = new TRow[this.RowCount];
			for (int i = 0; i < this.RowCount; i++)
			{
				rows[i] = this[i];
			}

			return rows;
		}
	}
}
